<!DOCTYPE html>
<html lang="en">

<head>
    <meta charset="UTF-8">
    <meta http-equiv="X-UA-Compatible" content="IE=edge">
    <meta name="viewport" content="width=device-width, initial-scale=1.0">
    <title>Document</title>
    <style>
        li {
            list-style: none;
            text-align: center;
            width: 200px;
            height: 50px;
            border: solid;
            font-size: 30px;
            border-radius: 10px;
        }
        
        .bgc {
            background-color: aqua;
        }
    </style>
</head>

<body>
    <!-- <div class="box">woshihezi</div> -->
    <!-- 
        1.事件源是谁
        2. 如何触发
        3.设置对应的处理函数
     -->

    <!-- <script>
        var box = document.querySelector('.box');
        box.addEventListener('click', haha);

        function haha(params) {
            box.innerHTML = 'hehe'
        };
    </script> -->

    <ul>
        <li>1</li>
        <li>2</li>
        <li>3</li>
        <li>4</li>
    </ul>

    <script>
        var lis = document.querySelectorAll('li');
        lis.forEach(function(ele) {
            ele.addEventListener('click', function() {
                // 进行排他
                // 干掉所以人 
                // 留下我自己
                for (let i = 0; i < lis.length; i++) {
                    lis[i].classList.remove('bgc');
                }
                this.classList.add('bgc')
            })
        })
    </script>
</body>

</html>